import { ActionContext } from 'vuex'
import { IUserState } from './state'
import { IStore } from '@/store/types'
import { login, getUserInfo } from '@/api/user'

export const actions = {
  // 登录
  async login({ commit }: ActionContext<IUserState, IStore>, params: any) {
    try {
      const res: any = await login(params)
      commit('SET_TOKEN', res.data.token)
      return Promise.resolve(res)
    } catch (error) {
      return Promise.reject(error)
    }
  },
  // 获取用户详情
  async getUserInfo({ commit }: ActionContext<IUserState, IStore>) {
    try {
      const res: any = await getUserInfo()
      commit('SET_USERINFO', res.data)
    } catch (error) {
      return Promise.reject(error)
    }
  }
  // 退出
}
